import ajax from '../utils/axios'

export async function login(params) {
  const res = await ajax.get(`/api/user/login`, { params })
  return res.data
}

export async function register(params) {
  const res = await ajax.post(`/api/user/userRegister`, params)
  return res.data
}

export async function userList(params) {
  const res = await ajax.post(`/api/user/getNormalUserList`, params)
  return res.data.data
}

export async function userDetail(userId) {
  const res = await ajax.get(`/api/user/detail?userId=${userId}`)
  return res.data.data
}

export async function deleteUser(ids) {
  const res = await ajax.post(`/api/user/delete?ids=${ids}`)
  return res.data.data
}

export async function updateUser(params) {
  const res = await ajax.post(`/api/user/update`, params)
  return res.data.data
}

export async function updatePwd(params) {
  const { userId, newPassword, password } = params
  const res = await ajax.post(
    `/api/user/updatePwd?userId=${userId}&newPassword=${newPassword}&password=${password}`
  )
  return res.data.data
}

export async function uploadAvatar(params) {
  const res = await ajax.post(`/api/user/uploadUserImage`, params)
  return res.data.data
}
